package com.lx.idgenerator.segement.bus;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lX
 * @version JDK 8
 * @className FillSegmentUpdater (此处以class为例)
 * @date 2024/10/28
 * @description 填充更新器
 */
public class FillSegmentUpdater {
    /**
     * 定义一个事件总线
     */
    private final EventBus eventBus = new AsyncEventBus("Segment-Updater-Event-Bus", new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(100),
            new ThreadPoolExecutor.CallerRunsPolicy()));

    /**
     * 注册监听器
     */
    public FillSegmentUpdater() {
        // 将事件注册到事件总线中
        eventBus.register(new FillSegmentListener());
    }

    /**
     * 发布事件
     * @param event
     */
    public void publishEvent(FillSegmentEvent event){
        eventBus.post(event);
    }


}
